﻿using System;
using System.Xml;
using Comdiv.QWeb.Files;

namespace Comdiv.QWeb.Utils {
	public class FileResolverBasedXmlUrlResolver : XmlUrlResolver {
		private readonly IFileNameResolver _files;

		public FileResolverBasedXmlUrlResolver(IFileNameResolver resolver) {
			_files = resolver;
		}

		public override Uri ResolveUri(Uri baseUri, string relativeUri) {
			if (relativeUri.StartsWith("#")) {
				return new Uri(_files.Resolve(relativeUri.Substring(1)));
			}
			return base.ResolveUri(baseUri, relativeUri);
		}
	}
}